package net.a6polo.a6poloweibo.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.a6polo.a6poloweibo.IndexActivity;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Matrix;

public class A6poloUtil {
	

	public static String dateToString(Date date, String type) {
        String str = null;
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        if (type.equals("SHORT")) {
            // 07-1-18
            format = DateFormat.getDateInstance(DateFormat.SHORT);
            str = format.format(date);
        } else if (type.equals("MEDIUM")) {
            // 2007-1-18
            format = DateFormat.getDateInstance(DateFormat.MEDIUM);
            str = format.format(date);
        } else if (type.equals("FULL")) {
            // 2007��1��18�� ������
            format = DateFormat.getDateInstance(DateFormat.FULL);
            str = format.format(date);
        }
        return str;
    }
	
	public static Bitmap scaleImg(Bitmap bm, int newWidth, int newHeight) {
		 // ͼƬԴ
	    // Bitmap bm = BitmapFactory.decodeStream(getResources()
	    // .openRawResource(id));
	    // ���ͼƬ�Ŀ��
	    int width = bm.getWidth();
	    int height = bm.getHeight();
	    // ������Ҫ�Ĵ�С
	    int newWidth1 = newWidth;
	    int newHeight1 = newHeight;
	    // �������ű���
	    float scaleWidth = ((float) newWidth1) / width;
	    float scaleHeight = ((float) newHeight1) / height;
	    // ȡ����Ҫ���ŵ�matrix����
	    Matrix matrix = new Matrix();
	    matrix.postScale(scaleWidth, scaleHeight);
	    // �õ��µ�ͼƬ
	    Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix,
	      true);
	    return newbm;
	}
	
	public static boolean saveToPreferences(Context ctx, String name, String key, String value) {
		SharedPreferences sp = ctx.getSharedPreferences(name, ctx.MODE_PRIVATE);

		SharedPreferences.Editor editor = sp.edit();
		editor.putString(key, value);
		return editor.commit();
	}
}
